package com.dingli.controller;

import com.dingli.framework.entity.Member;
import com.dingli.framework.util.Encryption;
import com.dingli.framework.util.Response;
import com.dingli.service.IMemberService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@CrossOrigin("*")
@RestController
@RequestMapping("/member")
@Api(tags = "成为会员")
public class MemberController {

    @Autowired
    private IMemberService iMemberService;

    @GetMapping("/MBlist")
    @ApiOperation("会员信息列表查询")
    public Response<PageInfo<Member>> MBlist(@ApiParam("查询条件")
                                         @RequestParam(required = false) String search,
                                           @ApiParam("页码") @RequestParam(required = false) Integer pageNum,
                                           @ApiParam("页面大小")
                                         @RequestParam(required = false) Integer pageSize) {
        return iMemberService.MBlist(search, pageNum, pageSize);
    }

    @PostMapping("/MBinsert")
    @ApiOperation("会员信息新增")
    public Object MBinsert(@ApiParam("会员信息") @RequestBody Member member) {
        member.setPassword(Encryption.md5(member.getPassword()));
        return iMemberService.MBinsert(member);
    }

    @GetMapping("/MBselectById")
    @ApiOperation("会员信息详情查看")
    public Response<Member> MBselectById(@ApiParam("用户ID") @RequestParam Long mbID) {
        return iMemberService.MBselectById(mbID);
    }

    @PostMapping("/MBupdateById")
    @ApiOperation("会员信息修改")
    public Response<Object> MBupdateById(@ApiParam("修改的用户信息") @RequestBody Member member) {

        return iMemberService.MBupdateById(member);
    }

    @GetMapping("/MBdeleteById")
    @ApiOperation("会员用户信息删除")
    public Response<Object> MBdeleteById(@ApiParam("用户ID") @RequestParam Long mbID) {
        return iMemberService.MBdeleteById(mbID);
    }

    @RequestMapping ("/slectArea")
    @CrossOrigin
    @ApiOperation("会员多条件模糊查询")
    public Response<List<Member>> selectArea(@ApiParam("会员地区,职位检索") @RequestParam String mbEseprovince){
        return iMemberService.selectArea(mbEseprovince);
    }

    /*@RequestMapping ("/selectName")
    @CrossOrigin
    @ApiOperation("会员企业名称模糊查询")
    public Response<List<Member>> selectName(@ApiParam("企业名称检索") @RequestParam String mbCompany){
        return iMemberService.selectName(mbCompany);
    }*/

    @PostMapping("/updateState")
    @ApiOperation("会员审核")
    public Response<Object> updateState(@ApiParam("审核会员通过") @RequestBody String mbId) {
        return iMemberService.updateState(mbId);
    }

    @PostMapping("/update")
    @ApiOperation("会员审核")
    public Response<Object> update(@ApiParam("审核会员不通过") @RequestBody String mbId) {

        return iMemberService.update(mbId);
    }

    @RequestMapping ("/selectState")
    @CrossOrigin
    @ApiOperation("审核查询")
    public  HashMap<Object, Object> selectState(@ApiParam("审核中查询") @RequestParam String mbState){
        Response<List<Member>> list = iMemberService.selectState(mbState);
        HashMap<Object, Object> ob = new HashMap<>();
        ob.put("Member",list);
        ob.put("size",list.getData().size());
        return ob;
    }

    @RequestMapping ("/selectState1")
    @CrossOrigin
    @ApiOperation("审核查询")
    public  HashMap<Object, Object> selectState1(@ApiParam("审核通过查询") @RequestParam String mbState){
        Response<List<Member>> list = iMemberService.selectState1(mbState);
        HashMap<Object, Object> yy = new HashMap<>();
        yy.put("Member",list);
        yy.put("size",list.getData().size());
        return yy;
    }

    @RequestMapping ("/All")
    @CrossOrigin
    @ApiOperation("会员统计")
    public HashMap<Object, Object> All(@ApiParam("会员统计") @RequestParam String mbId){
        Response<List<Member>> list = iMemberService.All(mbId);
        HashMap<Object, Object> yy = new HashMap<>();
//        wh.put("Member",list);
        yy.put("size",list.getData().size());
        return yy;
    }
}


